package com.ysd.twocrm.quartz;

import com.ysd.twocrm.entity.Orders;
import com.ysd.twocrm.mapper.OrdersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@EnableScheduling
public class OrdersQuartz {
    @Autowired
    private OrdersMapper ordersMapper;
    /*
     * @Description 每天0点0时0分执行这个方法
     * 查找到当天0点还没付款的订单然后删除
     * @param
     * @return void
     * @author liusupeng
     * @date 2020/5/25 9:09
     */
    @Scheduled(cron = "0 0 0 * * *")
    public void exitorders(){

        List<Orders> orders = ordersMapper.selectList(null);
        for(int i=0;i<orders.size();i++){
             if(orders.get(i).getOrderStatus()!=0){
                   ordersMapper.deleteById(orders.get(i).getOrderId());
             }
        }

    }
}
